
rm(list = ls())



# Check if the packages that we need are installed
want = c("haven", "ggthemes", "scales","stargazer",
         "sjmisc","tidyverse", "questionr","viridis","effects", 
         "mosaic", "knitr", "gt", "modelsummary", "fixest", "marginaleffects")
have = want %in% rownames(installed.packages())
# Install the packages that we miss
if ( any(!have) ) { install.packages( want[!have] ) }
# Load the packages
junk <- lapply(want, library, character.only = T)
# Remove the objects we created
rm(have, want, junk)



# load datasets
data2<-read_dta("~/Replication material/have_your_cake_data_2waves.dta")
data3<-read_dta("~/Replication material/have_your_cake_data_3waves.dta")


####  Expectation 1 / Market access after Limitation
#### fixest model (and clustered SEs)
## with dichotomized DVs


mod_expect1 <- list()


mod_expect1[["Market access - model"]] <- feols(EU_reaction0 ~ 
                                                    brexit_ukmodel +
                                                    interest_EU + heard_brexit +
                                                    immigration_std + populism_std +
                                                    demsat + ecosat + govapp +
                                                    SVPvote + left_right+ I(left_right^2) |
                                                    UserID + wave ,
                                                  data = data2, 
                                                  vcov= "cluster" , 
                                                  weights = ~weight3,
                                                  panel.id = ~UserID + wave)

mod_expect1[["Market access - model (int)"]] <- feols(EU_reaction0 ~ 
                                                          brexit_ukmodel*cooperation +brexit_ukmodel*I(cooperation^2) +
                                                          interest_EU + heard_brexit +
                                                          immigration_std + populism_std +
                                                          demsat + ecosat + govapp +
                                                          SVPvote + left_right + I(left_right^2)|
                                                          UserID + wave,
                                                        data = data2, 
                                                        vcov= "cluster" , 
                                                        weights = ~weight3,
                                                        panel.id = ~UserID + wave)


plot_cme(mod_expect1[["Market access - model (int)"]]  , effect = "brexit_ukmodel", condition =  "cooperation")+ 
  labs(title = "Marginal effect of assessment of Brexit strategy\non expected market access after approval of limitation initiative") + 
  xlab("Support for cooperation") + ylab("")

mod_expect1[["Market access - impact"]] <- feols(EU_reaction0 ~ 
                                                      brexit_impactUK +
                                                      interest_EU + heard_brexit +
                                                      immigration_std + populism_std +
                                                      demsat + ecosat + govapp +
                                                      SVPvote + left_right+ I(left_right^2) |
                                                      UserID + wave ,
                                                    data = data2, 
                                                    vcov= "cluster" , 
                                                    weights = ~weight3,
                                                    panel.id = ~UserID + wave)



mod_expect1[["Market access - impact (int)"]] <- feols(EU_reaction0 ~ 
                                                        brexit_impactUK*cooperation +brexit_impactUK*I(cooperation^2) +
                                                        interest_EU +heard_brexit +
                                                        immigration_std + populism_std +
                                                        demsat + ecosat + govapp +
                                                        SVPvote + left_right + I(left_right^2)|
                                                        UserID + wave,
                                                      data = data2, 
                                                      vcov= "cluster" , 
                                                      weights = ~weight3,
                                                      panel.id = ~UserID + wave)

plot_cme(mod_expect1[["Market access - impact (int)"]] , effect = "brexit_impactUK", condition =  "cooperation") + 
  labs(title = "Marginal effect of assessment of Brexit outcome\non expected market access after approval of limitation initiative") + 
  xlab("Support for cooperation") + ylab("")





mod_expect1[["Bilaterals' erosion - model"]]  <- feols(bilateral_erosion0 ~ 
                                                          brexit_ukmodel  +
                                                          interest_EU +heard_brexit+
                                                          immigration_std + populism_std +
                                                          demsat+ ecosat + govapp +
                                                          SVPvote + left_right + I(left_right^2)|
                                                          UserID + wave,
                                                        data = data3, 
                                                        vcov= "cluster" , 
                                                        weights = ~weight4,
                                                        panel.id = ~UserID + wave)

mod_expect1[["Bilaterals' erosion - model (int)"]] <- feols(bilateral_erosion0 ~ 
                                                           brexit_ukmodel*cooperation +brexit_ukmodel*I(cooperation^2) +
                                                           interest_EU +heard_brexit+
                                                           immigration_std + populism_std +
                                                           demsat+ ecosat + govapp +
                                                           SVPvote + left_right+ I(left_right^2) |
                                                           UserID + wave,
                                                         data = data3, 
                                                         vcov= "cluster" , 
                                                         weights = ~weight4,
                                                         panel.id = ~UserID + wave)

plot_cme(mod_expect1[["Bilaterals' erosion - model (int)"]], effect = "brexit_ukmodel", condition =  "cooperation")+ 
  labs(title = "Marginal effect of assessment of Brexit strategy\non expected consequences of erosion of bilateral treaties") + 
  xlab("Support for cooperation") + ylab("")


mod_expect1[["Bilaterals' erosion - impact"]]  <- feols(bilateral_erosion0 ~ 
                                                                             brexit_impactUK  +
                                                                             interest_EU +heard_brexit+
                                                                             immigration_std + populism_std +
                                                                             demsat+ ecosat + govapp +
                                                                             SVPvote + left_right + I(left_right^2)|
                                                                             UserID + wave,
                                                                           data = data3, 
                                                                           vcov= "cluster" , 
                                                                           weights = ~weight4,
                                                                           panel.id = ~UserID + wave)

mod_expect1[["Bilaterals' erosion - impact (int)"]] <- feols(bilateral_erosion0 ~ 
                                                                              brexit_impactUK*cooperation +brexit_impactUK*I(cooperation^2) +
                                                                              interest_EU +heard_brexit+
                                                                              immigration_std + populism_std +
                                                                              demsat+ ecosat + govapp +
                                                                              SVPvote + left_right + I(left_right^2)|
                                                                              UserID + wave,
                                                                            data = data3, 
                                                                            vcov= "cluster" , 
                                                                            weights = ~weight4,
                                                                            panel.id = ~UserID + wave)


plot_cme(mod_expect1[["Bilaterals' erosion - impact (int)"]], effect = "brexit_impactUK", condition =  "cooperation")+ 
  labs(title = "Marginal effect of assessment of Brexit impact\non expected consequences of erosion of bilateral treaties") + 
  xlab("Support for cooperation") + ylab("")


cm <- c( 'brexit_ukmodel' = 'Assessment of Brexit strategy',
         'brexit_impactUK' = 'Assessment of Brexit outcome',
         'brexit_ukmodel:political_knowledge'='Brexit strategy : Political knowledge',
         'brexit_ukmodel:cooperation'='Brexit strategy : Support for CH-EU cooperation',
         'brexit_ukmodel:I(cooperation^2)'='Brexit strategy : Support for CH-EU cooperation^2',
         'brexit_impactUK:political_knowledge' = 'Brexit outcome : Political knowledge',
         'brexit_impactUK:cooperation'='Brexit outcome : Support for CH-EU cooperation',
         'brexit_impactUK:I(cooperation^2)'='Brexit outcome : Support for CH-EU cooperation^2',
        'interest_EU' = 'Interest in Swiss-EU relations',
        'heard_brexit' = 'Heard of Brexit',
        'immigration_std' = 'Support for immigration (index)',
        'populism_std' = 'Populist attitude (index)',
        'demsat' = 'Dissatisfaction with democracy',
        'ecosat' = 'Economic dissatisfaction',
        'govapp' = 'Government dissatisfaction',
        'SVPvote' = 'SVP vote',
        'left_right' = 'Left-Right',
        'I(left_right^2)'= 'Left-Right^2')


modelsummary::msummary(mod_expect1, coef_map = cm, fmt = '%.3f', stars = c('*' = .1, 
                                                                           '**' = .05,
                                                                           '***' = .01))






p1<-plot_cme(mod_expect1[["Market access - model (int)"]] , effect = "brexit_ukmodel", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK as a model on\nexpected consequences of the limitation initiative") + 
  xlab("Support for cooperation") + ylab("Change in expected\nmarket access") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.1,.23)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )

p1
p2<-plot_cme(mod_expect1[["Market access - impact (int)"]] , effect = "brexit_impactUK", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK better off on\nexpected consequences of the limitation initiative") + 
  xlab("Support for cooperation") + ylab("Change in expected\nmarket access") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.1,.23)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )

p2

p3<-plot_cme(mod_expect1[["Bilaterals' erosion - model (int)"]] , effect = "brexit_ukmodel", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK as a model on\nexpected consequences of bilaterals' erosion") + 
  xlab("Support for cooperation") + ylab("Change in assessement\nof bilaterals' erosion") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.1,.23)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )
p3
p4<-plot_cme(mod_expect1[["Bilaterals' erosion - impact (int)"]] , effect = "brexit_impactUK", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK better off on\nexpected consequences of bilaterals' erosion") + 
  xlab("Support for cooperation") + ylab("Change in assessement\nof bilaterals' erosion") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.1,.23)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )

p4

g1 <- ggplotGrob(p1)
g2 <- ggplotGrob(p2)
g3 <- ggplotGrob(p3)
g4 <- ggplotGrob(p4)

grid::grid.newpage()
grid::grid.draw(rbind(cbind(g1, g3),  cbind(g2,g4)))




####  Vote 1 / Support for Limitation
#### fixest model (and clustered SEs)
## with dichotomized DVs


mod_vote1 <- list()


mod_vote1[["Limitation - model"]] <- feols(limitation_vote0 ~ 
                                                       brexit_ukmodel +
                                                       interest_EU + heard_brexit +
                                                       immigration_std + populism_std +
                                                       demsat + ecosat + govapp +
                                                       SVPvote + left_right + I(left_right^2)|
                                                       UserID + wave ,
                                                     data = data2, 
                                                     vcov= "cluster" , 
                                                     weights = ~weight3,
                                                     panel.id = ~UserID + wave)



mod_vote1[["Limitation - model (int)"]] <- feols(limitation_vote0 ~ 
                                                         brexit_ukmodel*cooperation +brexit_ukmodel*I(cooperation^2) +
                                                         interest_EU +heard_brexit +
                                                         immigration_std + populism_std +
                                                         demsat + ecosat + govapp +
                                                         SVPvote + left_right + I(left_right^2)|
                                                         UserID + wave,
                                                       data = data2, 
                                                       vcov= "cluster" , 
                                                       weights = ~weight3,
                                                       panel.id = ~UserID + wave)



plot_cme(mod_vote1[["Limitation - model (int)"]]  , effect = "brexit_ukmodel", condition =  "cooperation")+ 
  labs(title = "Marginal effect of assessment of Brexit strategy\non support for limitation initiative") + 
  xlab("Support for cooperation") + ylab("")



mod_vote1[["Limitation - impact"]] <- feols(limitation_vote0 ~ 
                                                        brexit_impactUK +
                                                        interest_EU + heard_brexit +
                                                        immigration_std + populism_std +
                                                        demsat + ecosat + govapp +
                                                        SVPvote + left_right+ I(left_right^2) |
                                                        UserID + wave ,
                                                      data = data2, 
                                                      vcov= "cluster" , 
                                                      weights = ~weight3,
                                                      panel.id = ~UserID + wave)



mod_vote1[["Limitation - impact (int)"]] <- feols(limitation_vote0 ~ 
                                                          brexit_impactUK*cooperation +brexit_impactUK*I(cooperation^2) +
                                                          interest_EU +heard_brexit +
                                                          immigration_std + populism_std +
                                                          demsat + ecosat + govapp +
                                                          SVPvote + left_right + I(left_right^2)|
                                                          UserID + wave,
                                                        data = data2, 
                                                        vcov= "cluster" , 
                                                        weights = ~weight3,
                                                        panel.id = ~UserID + wave)

plot_cme(mod_vote1[["Limitation - impact (int)"]] , effect = "brexit_impactUK", condition =  "cooperation") + 
  labs(title = "Marginal effect of assessment of Brexit outcome\non support for limitation initiative") + 
  xlab("Support for cooperation") + ylab("")






mod_vote1[["Insta - model"]]  <- feols(insta_vote0 ~ 
                                                        brexit_ukmodel  +
                                                        interest_EU +heard_brexit+
                                                        immigration_std + populism_std +
                                                        demsat+ ecosat + govapp +
                                                        SVPvote + left_right + I(left_right^2)|
                                                        UserID + wave,
                                                      data = data3, 
                                                      vcov= "cluster" , 
                                                      weights = ~weight4,
                                                      panel.id = ~UserID + wave)

mod_vote1[["Insta - model (int)"]] <- feols(insta_vote0 ~ 
                                                         brexit_ukmodel*cooperation +brexit_ukmodel*I(cooperation^2) +
                                                         interest_EU +heard_brexit+
                                                         immigration_std + populism_std +
                                                         demsat+ ecosat + govapp +
                                                         SVPvote + left_right+ I(left_right^2) |
                                                         UserID + wave,
                                                       data = data3, 
                                                       vcov= "cluster" , 
                                                       weights = ~weight4,
                                                       panel.id = ~UserID + wave)

plot_cme(mod_vote1[["Insta - model (int)"]], effect = "brexit_ukmodel", condition =  "cooperation")+ 
  labs(title = "Marginal effect of assessment of Brexit strategy\non opposition to Insta") + 
  xlab("Support for cooperation") + ylab("")




mod_vote1[["Insta - impact"]]  <- feols(insta_vote0 ~ 
                                                         brexit_impactUK  +
                                                         interest_EU +heard_brexit+
                                                         immigration_std + populism_std +
                                                         demsat+ ecosat + govapp +
                                                         SVPvote + left_right + I(left_right^2)|
                                                         UserID + wave,
                                                       data = data3, 
                                                       vcov= "cluster" , 
                                                       weights = ~weight4,
                                                       panel.id = ~UserID + wave)

mod_vote1[["Insta - impact (int)"]] <- feols(insta_vote0 ~ 
                                                          brexit_impactUK*cooperation +brexit_impactUK*I(cooperation^2) +
                                                          interest_EU +heard_brexit+
                                                          immigration_std + populism_std +
                                                          demsat+ ecosat + govapp +
                                                          SVPvote + left_right + I(left_right^2)|
                                                          UserID + wave,
                                                        data = data3, 
                                                        vcov= "cluster" , 
                                                        weights = ~weight4,
                                                        panel.id = ~UserID + wave)


plot_cme(mod_vote1[["Insta - impact (int)"]], effect = "brexit_impactUK", condition =  "cooperation")+ 
  labs(title = "Marginal effect of assessment of Brexit outcome \non opposition to Insta") + 
  xlab("Support for cooperation") + ylab("")




cm <- c('brexit_ukmodel' = 'Assessment of Brexit strategy',
        'brexit_ukmodel:political_knowledge'='Brexit strategy : Political knowledge',
        'brexit_ukmodel:cooperation'='Brexit strategy : Support for CH-EU cooperation',
        'brexit_ukmodel:I(cooperation^2)'='Brexit strategy : Support for CH-EU cooperation^2',
        'brexit_impactUK' = 'Assessment of Brexit outcome',
        'brexit_impactUK:political_knowledge' = 'Brexit outcome : Political knowledge',
        'brexit_impactUK:cooperation'='Brexit outcome : Support for CH-EU cooperation',
        'brexit_impactUK:I(cooperation^2)'='Brexit outcome : Support for CH-EU cooperation^2',
        'interest_EU' = 'Interest in Swiss-EU relations',
        'heard_brexit' = 'Heard of Brexit',
        'immigration_std' = 'Support for immigration (index)',
        'populism_std' = 'Populist attitude (index)',
        'demsat' = 'Dissatisfaction with democracy',
        'ecosat' = 'Economic dissatisfaction',
        'govapp' = 'Government dissatisfaction',
        'SVPvote' = 'SVP vote',
        'left_right' = 'Left-Right',
        'I(left_right^2)'= 'Left-Right^2' )


modelsummary::msummary(mod_vote1, coef_map = cm, fmt = '%.3f', stars = c('*' = .1, 
                                                                           '**' = .05,
                                                                           '***' = .01))




p1<-plot_cme(mod_vote1[["Limitation - model (int)"]]  , effect = "brexit_ukmodel", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK as a model on\nvote intentions on the limitation initiative") + 
  xlab("Support for cooperation") + ylab("Change in support\nfor the limitation initiative") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.14,.23)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )

p1
p2<-plot_cme(mod_vote1[["Limitation - impact (int)"]] , effect = "brexit_impactUK", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK better off on\nvote intentions on the limitation initiative") + 
  xlab("Support for cooperation") + ylab("Change in support\nfor the limitation initiative") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.14,.23)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )

p2

p3<-plot_cme(mod_vote1[["Insta - model (int)"]] , effect = "brexit_ukmodel", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK as a model on\nvote intentions on the framework agreement") + 
  xlab("Support for cooperation") + ylab("Change in support\nfor the farmework agreement") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.14,.23)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )
p3
p4<-plot_cme(mod_vote1[["Insta - impact (int)"]] , effect = "brexit_impactUK", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK better off on\nvote intentions on the framework agreement") + 
  xlab("Support for cooperation") + ylab("Change in support\nfor the framework agreement") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.14,.23)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )

p4

g1 <- ggplotGrob(p1)
g2 <- ggplotGrob(p2)
g3 <- ggplotGrob(p3)
g4 <- ggplotGrob(p4)

grid::grid.newpage()
grid::grid.draw(rbind(cbind(g1, g3),  cbind(g2,g4)))




      ### Replicate with full scaled DVs

####  Expectations
#### fixest model (and clustered SEs)
## with dichotomized DVs


mod_expect2 <- list()


mod_expect2[["Market access - model"]] <- feols(EU_reaction ~ 
                                                  brexit_ukmodel +
                                                  interest_EU + heard_brexit +
                                                  immigration_std + populism_std +
                                                  demsat + ecosat + govapp +
                                                  SVPvote + left_right+ I(left_right^2) |
                                                  UserID + wave ,
                                                data = data2, 
                                                vcov= "cluster" , 
                                                weights = ~weight3,
                                                panel.id = ~UserID + wave)

mod_expect2[["Market access - model (int)"]] <- feols(EU_reaction ~ 
                                                        brexit_ukmodel*cooperation +brexit_ukmodel*I(cooperation^2) +
                                                        interest_EU + heard_brexit +
                                                        immigration_std + populism_std +
                                                        demsat + ecosat + govapp +
                                                        SVPvote + left_right + I(left_right^2)|
                                                        UserID + wave,
                                                      data = data2, 
                                                      vcov= "cluster" , 
                                                      weights = ~weight3,
                                                      panel.id = ~UserID + wave)


plot_cme(mod_expect2[["Market access - model (int)"]]  , effect = "brexit_ukmodel", condition =  "cooperation")+ 
  labs(title = "Marginal effect of assessment of Brexit strategy\non expected market access after approval of limitation initiative") + 
  xlab("Support for cooperation") + ylab("")

mod_expect2[["Market access - impact"]] <- feols(EU_reaction ~ 
                                                   brexit_impactUK +
                                                   interest_EU + heard_brexit +
                                                   immigration_std + populism_std +
                                                   demsat + ecosat + govapp +
                                                   SVPvote + left_right+ I(left_right^2) |
                                                   UserID + wave ,
                                                 data = data2, 
                                                 vcov= "cluster" , 
                                                 weights = ~weight3,
                                                 panel.id = ~UserID + wave)



mod_expect2[["Market access - impact (int)"]] <- feols(EU_reaction ~ 
                                                         brexit_impactUK*cooperation +brexit_impactUK*I(cooperation^2) +
                                                         interest_EU +heard_brexit +
                                                         immigration_std + populism_std +
                                                         demsat + ecosat + govapp +
                                                         SVPvote + left_right + I(left_right^2)|
                                                         UserID + wave,
                                                       data = data2, 
                                                       vcov= "cluster" , 
                                                       weights = ~weight3,
                                                       panel.id = ~UserID + wave)

plot_cme(mod_expect2[["Market access - impact (int)"]] , effect = "brexit_impactUK", condition =  "cooperation") + 
  labs(title = "Marginal effect of assessment of Brexit outcome\non expected market access after approval of limitation initiative") + 
  xlab("Support for cooperation") + ylab("")





mod_expect2[["Bilaterals' erosion - model"]]  <- feols(bilateral_erosion ~ 
                                                         brexit_ukmodel  +
                                                         interest_EU +heard_brexit+
                                                         immigration_std + populism_std +
                                                         demsat+ ecosat + govapp +
                                                         SVPvote + left_right + I(left_right^2)|
                                                         UserID + wave,
                                                       data = data3, 
                                                       vcov= "cluster" , 
                                                       weights = ~weight4,
                                                       panel.id = ~UserID + wave)

mod_expect2[["Bilaterals' erosion - model (int)"]] <- feols(bilateral_erosion ~ 
                                                              brexit_ukmodel*cooperation +brexit_ukmodel*I(cooperation^2) +
                                                              interest_EU +heard_brexit+
                                                              immigration_std + populism_std +
                                                              demsat+ ecosat + govapp +
                                                              SVPvote + left_right+ I(left_right^2) |
                                                              UserID + wave,
                                                            data = data3, 
                                                            vcov= "cluster" , 
                                                            weights = ~weight4,
                                                            panel.id = ~UserID + wave)

plot_cme(mod_expect2[["Bilaterals' erosion - model (int)"]], effect = "brexit_ukmodel", condition =  "cooperation")+ 
  labs(title = "Marginal effect of assessment of Brexit strategy\non expected consequences of erosion of bilateral treaties") + 
  xlab("Support for cooperation") + ylab("")


mod_expect2[["Bilaterals' erosion - impact"]]  <- feols(bilateral_erosion ~ 
                                                          brexit_impactUK  +
                                                          interest_EU +heard_brexit+
                                                          immigration_std + populism_std +
                                                          demsat+ ecosat + govapp +
                                                          SVPvote + left_right + I(left_right^2)|
                                                          UserID + wave,
                                                        data = data3, 
                                                        vcov= "cluster" , 
                                                        weights = ~weight4,
                                                        panel.id = ~UserID + wave)

mod_expect2[["Bilaterals' erosion - impact (int)"]] <- feols(bilateral_erosion ~ 
                                                               brexit_impactUK*cooperation +brexit_impactUK*I(cooperation^2) +
                                                               interest_EU +heard_brexit+
                                                               immigration_std + populism_std +
                                                               demsat+ ecosat + govapp +
                                                               SVPvote + left_right + I(left_right^2)|
                                                               UserID + wave,
                                                             data = data3, 
                                                             vcov= "cluster" , 
                                                             weights = ~weight4,
                                                             panel.id = ~UserID + wave)


plot_cme(mod_expect2[["Bilaterals' erosion - impact (int)"]], effect = "brexit_impactUK", condition =  "cooperation")+ 
  labs(title = "Marginal effect of assessment of Brexit impact\non expected consequences of erosion of bilateral treaties") + 
  xlab("Support for cooperation") + ylab("")


cm <- c( 'brexit_ukmodel' = 'Assessment of Brexit strategy',
         'brexit_ukmodel:cooperation'='Brexit strategy : Support for CH-EU cooperation',
         'brexit_ukmodel:I(cooperation^2)'='Brexit strategy : Support for CH-EU cooperation^2',
         'brexit_impactUK' = 'Assessment of Brexit outcome',
         'brexit_impactUK:cooperation'='Brexit outcome : Support for CH-EU cooperation',
         'brexit_impactUK:I(cooperation^2)'='Brexit outcome : Support for CH-EU cooperation^2',
         'interest_EU' = 'Interest in Swiss-EU relations',
         'heard_brexit' = 'Heard of Brexit',
         'immigration_std' = 'Support for immigration (index)',
         'populism_std' = 'Populist attitude (index)',
         'demsat' = 'Dissatisfaction with democracy',
         'ecosat' = 'Economic dissatisfaction',
         'govapp' = 'Government dissatisfaction',
         'SVPvote' = 'SVP vote',
         'left_right' = 'Left-Right',
         'I(left_right^2)'= 'Left-Right^2')


modelsummary::msummary(mod_expect2, coef_map = cm, fmt = '%.3f', stars = c('*' = .1, 
                                                                           '**' = .05,
                                                                           '***' = .01))






p1<-plot_cme(mod_expect2[["Market access - model (int)"]] , effect = "brexit_ukmodel", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK as a model on\nexpected consequences of the limitation initiative") + 
  xlab("Support for cooperation") + ylab("Change in expected\nmarket access") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.3,.4)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )

p1
p2<-plot_cme(mod_expect2[["Market access - impact (int)"]] , effect = "brexit_impactUK", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK better off on\nexpected consequences of the limitation initiative") + 
  xlab("Support for cooperation") + ylab("Change in expected\nmarket access") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.3,.4)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )

p2

p3<-plot_cme(mod_expect2[["Bilaterals' erosion - model (int)"]] , effect = "brexit_ukmodel", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK as a model on\nexpected consequences of bilaterals' erosion") + 
  xlab("Support for cooperation") + ylab("Change in assessement\nof bilaterals' erosion") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.3,.4)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )
p3
p4<-plot_cme(mod_expect2[["Bilaterals' erosion - impact (int)"]] , effect = "brexit_impactUK", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK better off on\nexpected consequences of bilaterals' erosion") + 
  xlab("Support for cooperation") + ylab("Change in assessement\nof bilaterals' erosion") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.3,.4)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )

p4

g1 <- ggplotGrob(p1)
g2 <- ggplotGrob(p2)
g3 <- ggplotGrob(p3)
g4 <- ggplotGrob(p4)

grid::grid.newpage()
grid::grid.draw(rbind(cbind(g1, g3),  cbind(g2,g4)))




####  Vote 1 / Support for Limitation
#### fixest model (and clustered SEs)
## with dichotomized DVs


mod_vote2 <- list()


mod_vote2[["Limitation - model"]] <- feols(limitation_vote ~ 
                                             brexit_ukmodel +
                                             interest_EU + heard_brexit +
                                             immigration_std + populism_std +
                                             demsat + ecosat + govapp +
                                             SVPvote + left_right + I(left_right^2)|
                                             UserID + wave ,
                                           data = data2, 
                                           vcov= "cluster" , 
                                           weights = ~weight3,
                                           panel.id = ~UserID + wave)



mod_vote2[["Limitation - model (int)"]] <- feols(limitation_vote ~ 
                                                   brexit_ukmodel*cooperation +brexit_ukmodel*I(cooperation^2) +
                                                   interest_EU +heard_brexit +
                                                   immigration_std + populism_std +
                                                   demsat + ecosat + govapp +
                                                   SVPvote + left_right + I(left_right^2)|
                                                   UserID + wave,
                                                 data = data2, 
                                                 vcov= "cluster" , 
                                                 weights = ~weight3,
                                                 panel.id = ~UserID + wave)



plot_cme(mod_vote2[["Limitation - model (int)"]]  , effect = "brexit_ukmodel", condition =  "cooperation")+ 
  labs(title = "Marginal effect of assessment of Brexit strategy\non support for limitation initiative") + 
  xlab("Support for cooperation") + ylab("")



mod_vote2[["Limitation - impact"]] <- feols(limitation_vote ~ 
                                              brexit_impactUK +
                                              interest_EU + heard_brexit +
                                              immigration_std + populism_std +
                                              demsat + ecosat + govapp +
                                              SVPvote + left_right+ I(left_right^2) |
                                              UserID + wave ,
                                            data = data2, 
                                            vcov= "cluster" , 
                                            weights = ~weight3,
                                            panel.id = ~UserID + wave)



mod_vote2[["Limitation - impact (int)"]] <- feols(limitation_vote ~ 
                                                    brexit_impactUK*cooperation +brexit_impactUK*I(cooperation^2) +
                                                    interest_EU +heard_brexit +
                                                    immigration_std + populism_std +
                                                    demsat + ecosat + govapp +
                                                    SVPvote + left_right + I(left_right^2)|
                                                    UserID + wave,
                                                  data = data2, 
                                                  vcov= "cluster" , 
                                                  weights = ~weight3,
                                                  panel.id = ~UserID + wave)

plot_cme(mod_vote2[["Limitation - impact (int)"]] , effect = "brexit_impactUK", condition =  "cooperation") + 
  labs(title = "Marginal effect of assessment of Brexit outcome\non support for limitation initiative") + 
  xlab("Support for cooperation") + ylab("")






mod_vote2[["Insta - model"]]  <- feols(insta_vote ~ 
                                         brexit_ukmodel  +
                                         interest_EU +heard_brexit+
                                         immigration_std + populism_std +
                                         demsat+ ecosat + govapp +
                                         SVPvote + left_right + I(left_right^2)|
                                         UserID + wave,
                                       data = data3, 
                                       vcov= "cluster" , 
                                       weights = ~weight4,
                                       panel.id = ~UserID + wave)

mod_vote2[["Insta - model (int)"]] <- feols(insta_vote ~ 
                                              brexit_ukmodel*cooperation +brexit_ukmodel*I(cooperation^2) +
                                              interest_EU +heard_brexit+
                                              immigration_std + populism_std +
                                              demsat+ ecosat + govapp +
                                              SVPvote + left_right+ I(left_right^2) |
                                              UserID + wave,
                                            data = data3, 
                                            vcov= "cluster" , 
                                            weights = ~weight4,
                                            panel.id = ~UserID + wave)

plot_cme(mod_vote2[["Insta - model (int)"]], effect = "brexit_ukmodel", condition =  "cooperation")+ 
  labs(title = "Marginal effect of assessment of Brexit strategy\non opposition to Insta") + 
  xlab("Support for cooperation") + ylab("")




mod_vote2[["Insta - impact"]]  <- feols(insta_vote ~ 
                                          brexit_impactUK  +
                                          interest_EU +heard_brexit+
                                          immigration_std + populism_std +
                                          demsat+ ecosat + govapp +
                                          SVPvote + left_right + I(left_right^2)|
                                          UserID + wave,
                                        data = data3, 
                                        vcov= "cluster" , 
                                        weights = ~weight4,
                                        panel.id = ~UserID + wave)

mod_vote2[["Insta - impact (int)"]] <- feols(insta_vote ~ 
                                               brexit_impactUK*cooperation +brexit_impactUK*I(cooperation^2) +
                                               interest_EU +heard_brexit+
                                               immigration_std + populism_std +
                                               demsat+ ecosat + govapp +
                                               SVPvote + left_right + I(left_right^2)|
                                               UserID + wave,
                                             data = data3, 
                                             vcov= "cluster" , 
                                             weights = ~weight4,
                                             panel.id = ~UserID + wave)


plot_cme(mod_vote2[["Insta - impact (int)"]], effect = "brexit_impactUK", condition =  "cooperation")+ 
  labs(title = "Marginal effect of assessment of Brexit outcome \non opposition to Insta") + 
  xlab("Support for cooperation") + ylab("")




cm <- c('brexit_ukmodel' = 'Assessment of Brexit strategy',
        'brexit_ukmodel:cooperation'='Brexit strategy : Support for CH-EU cooperation',
        'brexit_ukmodel:I(cooperation^2)'='Brexit strategy : Support for CH-EU cooperation^2',
        'brexit_impactUK' = 'Assessment of Brexit outcome',
        'brexit_impactUK:cooperation'='Brexit outcome : Support for CH-EU cooperation',
        'brexit_impactUK:I(cooperation^2)'='Brexit outcome : Support for CH-EU cooperation^2',
        'interest_EU' = 'Interest in Swiss-EU relations',
        'heard_brexit' = 'Heard of Brexit',
        'immigration_std' = 'Support for immigration (index)',
        'populism_std' = 'Populist attitude (index)',
        'demsat' = 'Dissatisfaction with democracy',
        'ecosat' = 'Economic dissatisfaction',
        'govapp' = 'Government dissatisfaction',
        'SVPvote' = 'SVP vote',
        'left_right' = 'Left-Right',
        'I(left_right^2)'= 'Left-Right^2' )


modelsummary::msummary(mod_vote2, coef_map = cm, fmt = '%.3f', stars = c('*' = .1, 
                                                                         '**' = .05,
                                                                         '***' = .01))




p1<-plot_cme(mod_vote2[["Limitation - model (int)"]]  , effect = "brexit_ukmodel", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK as a model on\nvote intentions on the limitation initiative") + 
  xlab("Support for cooperation") + ylab("Change in support\nfor the limitation initiative") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.2,.3)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )

p1
p2<-plot_cme(mod_vote2[["Limitation - impact (int)"]] , effect = "brexit_impactUK", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK better off on\nvote intentions on the limitation initiative") + 
  xlab("Support for cooperation") + ylab("Change in support\nfor the limitation initiative") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.2,.3)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )

p2

p3<-plot_cme(mod_vote2[["Insta - model (int)"]] , effect = "brexit_ukmodel", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK as a model on\nvote intentions on the framework agreement") + 
  xlab("Support for cooperation") + ylab("Change in support\nfor the farmework agreement") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.2,.3)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )
p3
p4<-plot_cme(mod_vote2[["Insta - impact (int)"]] , effect = "brexit_impactUK", condition =  "cooperation") + 
  labs(title = "The effect of seeing the UK better off on\nvote intentions on the framework agreement") + 
  xlab("Support for cooperation") + ylab("Change in support\nfor the framework agreement") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.2,.3)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )

p4

g1 <- ggplotGrob(p1)
g2 <- ggplotGrob(p2)
g3 <- ggplotGrob(p3)
g4 <- ggplotGrob(p4)

grid::grid.newpage()
grid::grid.draw(rbind(cbind(g1, g3),  cbind(g2,g4)))




      ### Models with expectations as IVs and vote intentions as DVs



mod_vote3 <- list()


mod_vote3[["Limitation"]] <- feols(limitation_vote0 ~ 
                                             EU_reaction0 +
                                             interest_EU + heard_brexit +
                                             immigration_std + populism_std +
                                             demsat + ecosat + govapp +
                                             SVPvote + left_right + I(left_right^2)|
                                             UserID + wave ,
                                           data = data2, 
                                           vcov= "cluster" , 
                                           weights = ~weight3,
                                           panel.id = ~UserID + wave)



mod_vote3[["Limitation (int)"]] <- feols(limitation_vote0 ~ 
                                                   EU_reaction0*cooperation +EU_reaction0*I(cooperation^2) +
                                                   interest_EU +heard_brexit +
                                                   immigration_std + populism_std +
                                                   demsat + ecosat + govapp +
                                                   SVPvote + left_right + I(left_right^2)|
                                                   UserID + wave,
                                                 data = data2, 
                                                 vcov= "cluster" , 
                                                 weights = ~weight3,
                                                 panel.id = ~UserID + wave)







mod_vote3[["Insta"]]  <- feols(insta_vote0 ~ 
                                         bilateral_erosion0  +
                                         interest_EU +heard_brexit+
                                         immigration_std + populism_std +
                                         demsat+ ecosat + govapp +
                                         SVPvote + left_right + I(left_right^2)|
                                         UserID + wave,
                                       data = data3, 
                                       vcov= "cluster" , 
                                       weights = ~weight4,
                                       panel.id = ~UserID + wave)



mod_vote3[["Insta (int)"]] <- feols(insta_vote0 ~ 
                                              bilateral_erosion0*cooperation +bilateral_erosion0*I(cooperation^2) +
                                              interest_EU +heard_brexit+
                                              immigration_std + populism_std +
                                              demsat+ ecosat + govapp +
                                              SVPvote + left_right+ I(left_right^2) |
                                              UserID + wave,
                                            data = data3, 
                                            vcov= "cluster" , 
                                            weights = ~weight4,
                                            panel.id = ~UserID + wave)





cm <- c('EU_reaction0' = 'Expected market access',
        'EU_reaction0:cooperation'='Expected market access : Support for CH-EU cooperation',
        'EU_reaction0:I(cooperation^2)'='Expected market access : Support for CH-EU cooperation^2',
        'bilateral_erosion0' = "Positive assessment of bilaterals' erosion",
        'bilateral_erosion0:cooperation'="Assessment of bilaterals' erosion : Support for CH-EU cooperation",
        'bilateral_erosion0:I(cooperation^2)'="Assessment of bilaterals' erosion : Support for CH-EU cooperation^2",
        'interest_EU' = 'Interest in Swiss-EU relations',
        'heard_brexit' = 'Heard of Brexit',
        'immigration_std' = 'Support for immigration (index)',
        'populism_std' = 'Populist attitude (index)',
        'demsat' = 'Dissatisfaction with democracy',
        'ecosat' = 'Economic dissatisfaction',
        'govapp' = 'Government dissatisfaction',
        'SVPvote' = 'SVP vote',
        'left_right' = 'Left-Right',
        'I(left_right^2)'= 'Left-Right^2' )


modelsummary::msummary(mod_vote3, coef_map = cm, fmt = '%.3f', stars = c('*' = .1, 
                                                                         '**' = .05,
                                                                         '***' = .01))



p1<-plot_cme(mod_vote3[["Limitation (int)"]] , effect = "EU_reaction0", condition =  "cooperation") + 
  labs(title = "The effect of expected market access on\nsupport for limitation initiative") + 
  xlab("Support for cooperation") + ylab("Change in support\nfor the limitation initiative") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.15,.45)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )

p1

p2<-plot_cme(mod_vote3[["Insta (int)"]] , effect = "bilateral_erosion0", condition =  "cooperation") + 
  labs(title = "The effect of expected consequences of bilaterals'\nerosion on support for framework agreement") + 
  xlab("Support for cooperation") + ylab("Change in support\nfor the farmework agreement") + geom_hline(yintercept=0,  size=.12) + theme_bw()+
  scale_x_continuous(breaks=1:7)+ ylim(-.15,.45)+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )
p2

g1 <- ggplotGrob(p1)
g2 <- ggplotGrob(p2)

grid::grid.newpage()
grid::grid.draw(cbind(g1,g2))


      
      ### ROBUSTNESS TESTS
      ### cross-lagged models
  

data3 <- data3 %>% 
  group_by(UserID) %>% 
  mutate(insta_vote_lag = lag(insta_vote),
         insta_vote_lag0 = lag(insta_vote0),
         brexit_ukmodel_lag = lag(brexit_ukmodel),
         brexit_impactUK_lag = lag(brexit_impactUK)) %>% 
  ungroup



mod1 <- lm(insta_vote0 ~ insta_vote_lag0*wave  + brexit_ukmodel_lag*wave,
           data = data3, weights = weight4)
mod2 <- lm(brexit_ukmodel ~ insta_vote_lag0*wave + brexit_ukmodel_lag*wave ,
           data = data3, weights = weight4)
mod3 <- lm(insta_vote0 ~ insta_vote_lag0*wave  + brexit_impactUK_lag*wave,
           data = data3, weights = weight4)
mod4 <- lm(brexit_impactUK ~ insta_vote_lag0*wave + brexit_impactUK_lag*wave ,
           data = data3, weights = weight4)
stargazer(mod1, mod2,mod3,mod4,type = "text")
stargazer(mod1, mod2,mod3,mod4,type = "html",
          out="/Users/malet/Dropbox/ERC.DISINTEGRATION/WP1 Public Opinion/Papers/2021.Swiss_expectations/Tables/cross-lagged_models.html")



p1<-plot_model(mod1, type="pred", terms = c("wave","brexit_ukmodel_lag[1,5]"),
               title = "Vote change on framework agreement", 
               axis.title = c("Wave","Probability of support\nfor framework agreement"))+ 
  theme_bw() + theme(legend.position = "bottom")+ ylim(0,1)+
  scale_color_discrete(name = "", labels = c("UK a cautionary example", "UK a role model"))+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )
p1
p2<-plot_model(mod2, type="pred", terms = c("wave","insta_vote_lag0[0,1]"),
               title = "Change in assessment of UK as a model", 
               axis.title = c("Wave","Assessment of\nUK as a model"))+ ylim(1,5)+
  theme_bw() + theme(legend.position = "bottom")+ scale_color_discrete(name = "", labels = c("Against InstA", "In favour of InstA"))+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )
p2
library(ggpubr)
ggarrange(p1,p2)



p3<-plot_model(mod3, type="pred", terms = c("wave","brexit_impactUK_lag[1,5]"),
               title = "Vote change on framework agreement", 
               axis.title = c("Wave","Probability of support\nfor framework agreement"))+ 
  theme_bw() + theme(legend.position = "bottom")+ ylim(0,1)+
  scale_color_discrete(name = "", labels = c("UK worse off", "UK better off after Brexit"))+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )
p3
p4<-plot_model(mod2, type="pred", terms = c("wave","insta_vote_lag0[0,1]"),
               title = "Change in assessment of Brexit impact on UK", 
               axis.title = c("Wave","Assessment of\nBrexit impact on UK"))+ ylim(1,5)+
  theme_bw() + theme(legend.position = "bottom")+ scale_color_discrete(name = "", labels = c("Against InstA", "In favour of InstA"))+
  theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
        text=element_text(family = "LM Roman 10", size=13),
        axis.text=element_text(size=13, color = "black"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        plot.title = element_text(hjust = 0.5, size = 13, face ="bold"),
        strip.background = element_rect(colour="black",
                                        fill="white")   )
p4
library(ggpubr)
ggarrange(p3,p4)

